package org.example.learn.javaagent.apply_demo.plugin.impl.link;

import net.bytebuddy.description.method.MethodDescription;
import net.bytebuddy.description.type.TypeDescription;
import net.bytebuddy.matcher.ElementMatcher;
import net.bytebuddy.matcher.ElementMatchers;
import org.example.learn.javaagent.apply_demo.plugin.IPlugin;
import org.example.learn.javaagent.apply_demo.plugin.InterceptPoint;

// 链路追踪
public class LinkPlugin implements IPlugin {

    @Override
    public String name() {
        return "link";
    }

    @Override
    public InterceptPoint[] buildInterceptPoint() {
        return new InterceptPoint[]{new InterceptPoint() {
            @Override
            public ElementMatcher<TypeDescription> buildTypesMatcher() {
//                return ElementMatchers.named("org.example.learn.javaagent.apply_demo.test.ApplyRun");
                return ElementMatchers.nameStartsWith("org.example.learn.javaagent.apply_demo.test");
            }

            @Override
            public ElementMatcher<MethodDescription> buildMethodsMatcher() {
                return ElementMatchers.isMethod().and(ElementMatchers.any()).and(ElementMatchers.not(ElementMatchers.nameStartsWith("main")));
            }
        }};
    }

    @Override
    public Class<?> adviceClass() {
        return LinkAdvice.class;
    }
}
